﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_DAL;
using Zor_Tools;

namespace Zor_Bll
{
    public class AcceptanceBrowse_Bll<T> where T : class
    {
        /// <summary>
        /// 获取受理单信息列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        public static List<T> GetPageList(dynamic Model,int index, out int TotalCount,string where)
        {
            int Dtid = RequestSession.GetSessionUser().DT_Id;
            int Isadmin = RequestSession.GetSessionUser().Is_Admin;
            var sqlSurch = " 1=1 ";
            if (Isadmin == 1 || Dtid ==16)
            {
                sqlSurch = " 1=1 ";
            }
            else
            {
                sqlSurch = "( StreetOfficeID = " + Dtid + " or Dt_ParentId = "+Dtid+" )";
            }
            if (Model.StreetOffice != null)
            {
                sqlSurch += " and " + " StreetOffice like '%" + Model.StreetOffice + "%'  ";
            }
            if (Model.Community != null)
            {
                sqlSurch += " and " + " Community like '%" + Model.Community + "%'  ";
            }
            if (Model.Acceptance_TicketNumber != null)
            {
                sqlSurch += " and " + " Acceptance_TicketNumber = '" + Model.Acceptance_TicketNumber + "'  ";
            }           
            if (Model.AcceptanceState != null)
            {
                sqlSurch += " and " + " AcceptanceState = '" + Model.AcceptanceState + "'  ";
            }
            if (Model.NatPer_Name != null)
            {
                sqlSurch += " and " + " NatPer_Name like '%" + Model.NatPer_Name + "%'  ";
            }
            if (Model.NatPer_Phone != null)
            {
                sqlSurch += " and " + " NatPer_Phone = '" + Model.NatPer_Phone + "'  ";
            }
            if (Model.Acceptance_TaxStartTime != null && Model.Acceptance_TaxEndTime==null)
            {
                int StartTime = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Acceptance_TaxStartTime.ToString()));
                sqlSurch += " and " + " Acceptance_TaxStartTime = '" + StartTime + "'  ";
            }
            if (Model.Acceptance_TaxEndTime != null && Model.Acceptance_TaxStartTime == null)
            {
                int EndTime = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Acceptance_TaxEndTime.ToString()));
                sqlSurch += " and " + " Acceptance_TaxEndTime = '" + EndTime + "'  ";
            }
            if (Model.Acceptance_TaxStartTime != null && Model.Acceptance_TaxEndTime != null)
            {
                int StartTime = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Acceptance_TaxStartTime.ToString()));
                int EndTime = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Acceptance_TaxEndTime.ToString()));
                sqlSurch += " and " + " Acceptance_TaxStartTime between '" + StartTime + "' and '" + EndTime + "'  ";
            }
            if (Model.Hsattribute != null)
            {
                sqlSurch += " and " + " Hsattribute = '" + Model.Hsattribute + "'  ";
            }
            if (Model.HsNature != null)
            {
                sqlSurch += " and " + " HsNature = '" + Model.HsNature + "'  ";
            }
            if (Model.Acceptance_Address != null)
            {
                sqlSurch += " and " + " Acceptance_Address like '%" + Model.Acceptance_Address + "%'  ";
            }
            return PagerHelp<T>.GetPagerList(index, "V_AcceptanceBrowse", "Community", out TotalCount, sqlSurch);
        }
    }
}
